<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>

<%@page import="com.yaodian100.core.common.utils.ServerValue"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" href="/css/share.css" type="text/css" media="screen,print" />
<script type="text/javascript" src="/js/pageable.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script language="javascript">
$().ready(function(){
	
	$("#codeTip").hide();
	$("#iv").attr("src","<%=ServerValue.getFrontContextPath()%>/servlet/imageValid.jpg?"+Math.random());
	
	$("#chang_image").click(function(){
		$("#iv").attr("src","<%=ServerValue.getFrontContextPath()%>/servlet/imageValid.jpg?"+Math.random());
	});


	function openLogin(tp){
		openDialog("分享／通知朋友",$("#loginBox").load("<%=ServerValue.getFrontContextPath()%>/sharing/loginMail.do?tp="+tp),550,'auto');
	}	
	$("#163").click(function(){
		openLogin("163");			
	});
	$("#sina").click(function(){
		openLogin("sina");	
	});
	$("#gmail").click(function(){
		openLogin("gmail");
	});

	$("#sendMail").click(function(){
		//$("#sendMailForm").submit();
		
		vaildForm();
	});

	//$("#sendMailForm").submit(function(){	
	function vaildForm(){	
		 var isCorrect = true;	
		 
		 <%--先把最後面的逗號去除--%>
		$("#contacts").val(jQuery.trim($("#contacts").val()).toLowerCase());
		var mailLength = $("#contacts").val().length;
		if(mailLength>0){			
			if( $("#contacts").val().substring(mailLength-1,mailLength)==','){
				 $("#contacts").val($("#contacts").val().substring(0,mailLength-1));
			}
		}
	      
    	//$("#contacts").val(jQuery.trim($("#contacts").val()).toLowerCase());  
		if($("#contacts").val() == ""){
			alertDialog("发送失败","<div class=\"alert-caution\"><p>您朋友的邮箱格式有误，<br>请再检查一下。</p></div>","",300,180);
			isCorrect = false;			
		}else{
			
			var mails = $("#contacts").val().split(",");
			
			var wrongmails = "";
			for(var i=0;i<mails.length;i++){
				if(mails[i].match(/.+@.+\..+/)==null ||mails[i].indexOf(' ')>=0 || chineseCount(mails[i])>0){					
					wrongmails = wrongmails+","+mails[i];
					isCorrect = false;					
				}
			}
			if(wrongmails.length>0){							
				alertDialog("发送失败","<div class=\"alert-caution\"><p>您朋友的邮箱格式有误，<br>请再检查一下。</p></div>","",300,180);
			}
		}

		var finalCheck = false;

		if(($("#ccode").attr('value') == "")){
    	  	$("#ccode").focus();	
       		$("#codeTip").html('请输入校验码');
       		$("#codeTip").show();
       		isCorrect = false;
      	}else{
    	  $.post("<%=ServerValue.getFrontContextPath()%>/shopping/jsonChkValidateNum.do",{ccode:$("#ccode").val()},
    			  function (ccodeResult){
    		  	if(ccodeResult == "error"){
    					$("#ccode").focus();	
    					$("#codeTip").html('验证码错误，请重新输入');
    					$("#iv").attr("src","<%=ServerValue.getFrontContextPath()%>/servlet/imageValid.jpg?"+Math.random());
    					$("#codeTip").show();	
    					isCorrect = false;
    										
    				}else{
    					$("#codeTip").hide();
    					if(isCorrect==true){
    						$("#sendMail").hide();
    						$("#sendMailForm").submit();
    					}
    				}
    	  },"json");
      	}	

	     return false;
		
	}
	

	function chineseCount(word){
	    var length=0;
	    for(var cc=0;cc<word.length;cc++){
	       var c = word.charCodeAt(cc);
	      if (!(c>=32&&c<=126)) length++;
	    }
	    return length;
	}
	
	
	
});
</script>
</head>
<body>
<%if (null != request.getHeader("Referer")) {%>
<div id="main" class="share">
    <div class="content">
      <h2>分享／通知朋友</h2>
            <div class="share-title"><img src="/images/share/titlepix.jpg" alt=""  /></div>

    		<ul class="share-info">
          		<li><strong>发现了一个好东东，快透过下列工具分享给您的朋友!!</strong></li>
    	    </ul>
    </div>
    <form action="sendMail.do" id="sendMailForm" name="sendMailForm" method="post" onSubmit="return false;">
    <div class="sharebox">
       <h2>通知您的朋友</h2>
       <input type="hidden" name="snsType" id="snsType" value="none"/>
       <input type="hidden" name="chk" id="chk" value="${chk}"/>
       <input type="hidden" name="pageType" id="pageType" value="${pageType}"/>
       <input type="hidden" name="pageData" id="pageData" value="${pageData}"/>
            <ul>
            <li><strong>标题：</strong><span class="boderline">嗨，我在耀点100发现了个好东东分享给你～</span></li>

            <li><img src="/images/share/line.gif" alt=""  /></li>
            <li><strong>朋友邮箱：</strong><span>&nbsp;(多个收件人，请用逗号隔开)</span></li>
            <li><textarea name="contacts" id="contacts" style="width:330px;" rows="3"></textarea><span id="mailTip"></span></li>		
            <li><strong>信息预覧：</strong></li>
            <li class="boderline">您好,<p>您的朋在耀点100发现了一个好东东！</p><p>立即点击去瞧一瞧！</p></li>           
            <li><img src="/images/share/line.gif" alt=""  /></li>
            <li><strong>验证码：</strong><span><input name="ccode" type="text" id="ccode" style="width:90px;"  autocomplete="off" /></span>
            <span class="type-3 txt-L"><img id="iv" name="iv"></span> <a href="#" id="chang_image">看不清？换张图片</a>
            <span style="display:block"><span id="codeTip" class="msg rn" style="display:none">请输入校验码</span></span>
            </li>                     
             <div class="bt-box2"><a href="#" class="sendf" title="通知朋友" id="sendMail"></a></div>
            </ul>
            <p class="bmloc"><img src="/images/share/bg_bottom384.gif" alt=""  /></p>
      </div>
      
    <div class="sharebox">

       <h2>快速通知朋友</h2>
            <ul>
            <li>使用下列服务快速通知朋友时，<br/>您将会需要进行<em>邮箱登入</em>，就可以很快完成通知。</li>
            <li><img src="/images/share/line.gif" alt=""  /></li>
            <li class="txtLarge">通知下列邮箱中的联系人:</li>
            <li>

                  <div class="bt-box">
                   <a title="通知163上的朋友" class="m163" href="#" id="163"></a>
                   <a title="通知sina上的朋友" class="sina" href="#" id="sina"></a>           
                   <a title="通知Gmail上的朋友" class="gmail" href="#" id="gmail"></a>                  
                  </div>
            </li>
            </ul>
            <p class="bmloc"><img src="/images/share/bg_bottom384.gif" alt=""  /></p>
            <div class="backpd">

            </div>
      </div>
      </form>	
  </div>
<div id="dialog"></div>
<div id="loginBox"></div>
<div id="friendList"></div>
<div id="loaging" ></div>
<div id="listing" ></div>
<%}%>

</body>
</html>